package com.example.myapplication1.loldemo.behavior;

import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.core.widget.NestedScrollView;

import com.example.myapplication1.R;


/**
 * Copyright (C), 2020, 重庆八进制有限公司
 *
 * @author: weng
 * @last-modifier: weng
 * @version: 1.0
 * @create-date: 2020/11/23 16:18
 * @last-modify-date: 2020/11/23 16:18
 * @description:
 */
public class RecycleViewLayoutBehavior extends CoordinatorLayout.Behavior {

    public boolean isinit;
    public RecycleViewLayoutBehavior() {
    }

    public RecycleViewLayoutBehavior(Context context, AttributeSet attrs) {
        super(context, attrs);

    }

    @Override
    public boolean layoutDependsOn(CoordinatorLayout parent, View child, View dependency) {

        return dependency.getId() == R.id.tablayout;
    }

    @Override
    public boolean onInterceptTouchEvent(@NonNull CoordinatorLayout parent, @NonNull View child, @NonNull MotionEvent ev) {

        return super.onInterceptTouchEvent(parent, child, ev);

    }
    @Override
    public boolean onDependentViewChanged(CoordinatorLayout parent, View child, View dependency) {
          if (!isinit){
               isinit = true;
              int height = parent.findViewById(R.id.headercontainer).getHeight() + dependency.getMeasuredHeight();
              child.setTranslationY(height);
              Log.e("tag","onDependentViewChanged");

          }

        return true;
    }

    @Override
    public void onNestedScroll(@NonNull CoordinatorLayout coordinatorLayout, @NonNull View child, @NonNull View target, int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed, int type, @NonNull int[] consumed) {
        super.onNestedScroll(coordinatorLayout, child, target, dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed, type, consumed);

    }



    @Override
    public boolean onStartNestedScroll(@NonNull CoordinatorLayout coordinatorLayout, @NonNull View child, @NonNull View directTargetChild, @NonNull View target, int axes, int type) {
//        Log.e("tag","onStartNestedScroll2");
        return true;
    }

}
